package com.tree.jpa.repository;

import com.tree.jpa.entity.UserEntity;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

/**
 * @ClassName com.tree.jpa.repository
 * Description: <类功能描述>. <br>
 * <p>
 *  具体使用方法参考如下链接或者截图: doc/JPA内置支持关键字.jpg
 *  https://docs.spring.io/spring-data/jpa/docs/2.2.4.RELEASE/reference/html/#jpa.query-methods.query-creation
 * </p>
 * @Author tree
 * @Date 2020-02-08 15:58
 * @Version 1.0
 */
public interface UserRepository extends JpaRepository<UserEntity,Long> {

    /**
     * 使用自定义方法
     * @param userName
     * @return
     */
    List<UserEntity> findByUserNameStartingWith(String userName);

//    List<UserEntity> findByUserNameStartingWithOrOrderByIdDesc(String userName);

    UserEntity findByUserName(String userName);

    List<UserEntity> findByIdGreaterThan(Long id);

    /**
     * 使用Query
     * 传参使用：fieldName
     * @param roleId
     * @return
     */
    @Query("SELECT U FROM UserEntity U ,UserRoleEntity RU WHERE U.id = RU.uid AND RU.rid = :roleId")
    List<UserEntity> findUsersByRole(@Param("roleId") Long roleId);

    /**
     * page
     *
     */


    /**
     * top
     */
    List<UserEntity> findTopByUserName(String userName);




}
